package cn.juque.datapipeline.handler;

import cn.juque.common.base.BaseResponseVO;
import cn.juque.common.base.PageInfo;
import cn.juque.common.constants.MessageEnum;
import cn.juque.common.exception.AppException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author nuoka
 * @version 1.0.0
 * <li>IntelliJ IDEA</li>
 * <li>cn.juque.consumer.handler</li>
 * @date 2021/7/25 14:43
 **/
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandle {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public BaseResponseVO<?> exceptionHandler(Exception e) {
        log.error("GlobalExceptionHandle catch error", e);
        return new BaseResponseVO<>(MessageEnum.SYSTEM_ERROR, null, new PageInfo());
    }

    @ExceptionHandler(AppException.class)
    @ResponseBody
    public BaseResponseVO<?> appHandler(AppException e) {
        return new BaseResponseVO<>(e.getCode(), e.getMessage());
    }
}
